#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main(int argc, char *argv)
{
	int sockfd = -1;
	int ret = 0;

	sockfd = socket(AF_INET, SOCK_DGRAM, 0);
	printf("sockfd = %d\n", sockfd);

	struct sockaddr_in myaddr;
	myaddr.sin_family = AF_INET;
	myaddr.sin_addr.s_addr = INADDR_ANY;
	myaddr.sin_port = htons(60001);

	if(bind(sockfd,(struct sockaddr*)&myaddr,sizeof(myaddr))<0)
	{
		perror("bind err");
	    close(sockfd);
	    return -1;
	}

	char buf[1024];
	size_t len = 0;
	while(1)
	{
		ret = recvfrom(sockfd, buf, sizeof(buf), 0, NULL, NULL);
		if ( ret > 0 ) {
			buf[ret]= 0;
			printf("buf: %s\n", buf);
		}
	}
	return 0;
}

